﻿@{
    ViewBag.Title = "管理登录 - 后台管理系统";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{
    <link href='/yisha/css/login.css' rel="stylesheet" />
    <script src="/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <style>
        .login-left {
            position: absolute;
            margin-top: 200px;
            margin-left:200px;
        }
            .login-left p {
                margin-top: -10px;
                text-align: left;
                color: #808080;
                font-size: 16px;
                line-height: 30px;
            }
        .login-left-bg {
            background: url(/images/login-left-bg.png) left no-repeat;
            width: 765px;
            height: 500px;
            margin-top: 20px;
        }
    </style>
}
<div class="login-left">
    <p style="width:550px;text-align:left;">GeneralNetCore是一套快速开发的后端框架，此系统为《理工邦》平台，主要是帮助理工人士找工作、找朋友及找恋人。</p>
    <div class="login-left-bg"></div>
</div>

<div class="login-panel">
    <div class="row section">
        <div class="col-sm-12">
            <form id="form">
                <p style="text-align: center;margin-bottom: 30px;font-size: 20px;">用户登录</p>
                <input id="userName" name="userName" class="form-control uname" col="UserName" type="text" placeholder="登录账号" value="" />
                <input id="password" name="password" class="form-control pword m-b" col="Password" type="password" placeholder="登录密码" value="" />
                <div class="row">
                    <div class="col-xs-6">
                        <input id="captchaCode" name="captchaCode" type="text" col="CaptchaCode" class="form-control code" placeholder="验证码" maxlength="3">
                    </div>
                    <div class="col-xs-6" style="text-align:right">
                        <a href="javascript:void(0);" title="点击更换验证码">
                            <img id="imgCaptchaCode" src='@Url.Content("~/Admin/GetCaptchaImage")' height="34" />
                        </a>
                    </div>
                </div>
                <!--<div class="checkbox-custom">
        <input id="rememberMe" name="rememberMe" type="checkbox"> <label for="rememberMe">记住我</label>
    </div>-->
                <button class="btn btn-success btn-block" style="background:#1E9FFF;border:0px" onclick="loginForm(); return false;">登录</button>
            </form>
        </div>
    </div>
    <div class="login-footer" style="display:none">
        <div style="text-align:center">
            &copy; 2019-@DateTime.Now.Year All Rights Reserved. <a href="http://ourres.com" target="_blank" style="color:white">GeneralNetCore</a><br>
            <br>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        if ($.cookie('RememberMe') == 1) {
            $("#rememberMe").prop("checked", true);
           
        }
        $("#rememberMe").click(function () {
            if ($(this).prop("checked")) {
                $.cookie('RememberMe', 1, { expires: 30, path: '/' });
            }
        });

        $("#imgCaptchaCode").click(function () {
            $(this).attr("src", '@Url.Content("~/Admin/GetCaptchaImage")' + '?t=' + new Date().getTime());
        });

        $("#form").validate({
            rules: {
                userName: { required: true },
                password: { required: true }
            }
        });

        $.validator.setDefaults({
            submitHandler: function () {
                loginForm();
            }
        });
    });

    function loginForm() {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls();
            ys.ajax({
                url: '@Url.Content("~/Api/Admin/LoginProcess")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.code == 1) {
                        ys.msgSuccess(obj.message);
                        redirectToIndex();
                    }
                    else {
                        ys.msgError(obj.message);
                        changecode();
                    }
                }
            });
        }
    }

    function changecode() {
        $("#imgCaptchaCode").attr("src", "/admin/GetCaptchaImage?" + Math.random());
    }


    function redirectToIndex() {
        location.href = '@Url.Content("~/Admin/Index")';
    }
</script>